package com.party.core.service.mall.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.mall.MallOrderFromReadDao;
import com.party.core.dao.write.mall.MallOrderFormWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.mall.MallOrderForm;
import com.party.core.service.mall.IMallGoodsService;
import com.party.core.service.mall.IMallOrderFormService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @ClassName MallOrderFormService
 * @Description
 * @Author shenliuhai
 * @Date 2020/4/17 10:59
 **/
@Service
public class MallOrderFormService implements IMallOrderFormService {


    @Autowired
    private MallOrderFromReadDao mallOrderFromReadDao;

    @Autowired
    private MallOrderFormWriteDao mallOrderFormWriteDao;

    @Override
    public String insert(MallOrderForm mallOrderForm) {
        BaseModel.preInsert(mallOrderForm);
        boolean result = mallOrderFormWriteDao.insert(mallOrderForm);
        if (result) {
            return mallOrderForm.getId();
        }
        return null;
    }

    @Override
    public boolean update(MallOrderForm mallOrderForm) {
        mallOrderForm.setUpdateDate(new Date());
        return mallOrderFormWriteDao.update(mallOrderForm);
    }

    @Override
    public boolean deleteLogic(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return mallOrderFormWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return mallOrderFormWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return mallOrderFormWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return mallOrderFormWriteDao.batchDelete(ids);
    }

    @Override
    public MallOrderForm get(String id) {
        return mallOrderFromReadDao.get(id);
    }

    @Override
    public List<MallOrderForm> listPage(MallOrderForm mallOrderForm, Page page) {
        return mallOrderFromReadDao.listPage(mallOrderForm,page);
    }

    @Override
    public List<MallOrderForm> list(MallOrderForm mallOrderForm) {
        return mallOrderFromReadDao.listPage(mallOrderForm,null);
    }

    @Override
    public List<MallOrderForm> batchList(Set<String> ids, MallOrderForm mallOrderForm, Page page) {
        if (CollectionUtils.isEmpty(ids)) {
            return Collections.EMPTY_LIST;
        }
        return mallOrderFromReadDao.batchList(ids,new HashMap<>(),page);
    }
}
